﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace SimpleLiteForm.Translator
{
    public class MockTranslationService : ITranslationService
    {
        /// <summary>
        /// The singleton instance.
        /// </summary>
        private static ITranslationService _instance;

        /// <summary>
        /// The string for unknown translations.
        /// </summary>
        public const string UNKNOWN_TRANSLATION = "?";
 
        /// <summary>
        /// Creates a new TranslationService instance.
        /// </summary>
        private MockTranslationService()
        {

        }

        /// <summary>
        /// Translates a string with auto source language detection.
        /// </summary>
        /// <param name="inputString">The input string to translate.</param>
        /// <param name="targetLanguage">The target language to tranlsate to.</param>
        /// <returns>The translated text or <code>UNKNOWKN_TRANSLATION</code> if not successful.</returns>
        public string Translate(string inputString, CultureInfo targetLanguage)
        {
            return Translate(inputString, targetLanguage, null);
        }

        /// <summary>
        /// Translates a string.
        /// </summary>
        /// <param name="inputString">The input string to translate.</param>
        /// <param name="targetLanguage">The target language to tranlsate to.</param>
        /// <param name="sourceLanguage">The source language to tranlate from.</param>
        /// <returns>The translated text or <code>UNKNOWKN_TRANSLATION</code> if not successful.</returns>
        public string Translate(string inputString, CultureInfo targetLanguage, CultureInfo sourceLanguage)
        {
            if (string.IsNullOrEmpty(inputString) ||
                !GetSupportedLanuages().Contains(targetLanguage.TwoLetterISOLanguageName))
                return UNKNOWN_TRANSLATION;
            else
                return inputString.ToUpper();
        }

        /// <summary> 
        /// Uses the TranslatorContainer to identify the Language in which inputString  
        /// was written</summary> 
        /// <param name="inputString">The string to identify</param> 
        /// <returns>The Language Code for a language that this string could represent, 
        /// or null if one is not found.</returns> 
        public string DetectSourceLanguage(string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
                return null;
            else
                return "en";
        }

        /// <summary>
        /// Gets a list of the supported languages.
        /// </summary>
        /// <returns>The supported language list.</returns>
        public IList<string> GetSupportedLanuages()
        {
            var languageList = new List<string>();
            languageList.Add("en");
            languageList.Add("de");
            languageList.Add("cn");
            return languageList;
        }

        /// <summary>
        /// Gets the translation service instance.
        /// </summary>
        public static ITranslationService Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new MockTranslationService();
                return _instance;
            }
        }
    }
}
